package com.lee.account.utils;

import java.util.Map;

import com.alibaba.fastjson.JSONObject;

/**
 * 返回值封装
 * @author liyou
 * @date 2019年9月3日 下午4:02:38
 */
public class R extends JSONObject {
	private static final long serialVersionUID = -1582806451085364477L;
	
	private static final String PROPERTY_SUCCESS = "success";
	private static final String PROPERTY_MESSAGE = "msg";
	
	private static final String SERVER_ERROR = "服务端错误";
	private static final String PARAMS_ERROR = "参数错误";


	public R() {
		put(PROPERTY_SUCCESS, Boolean.valueOf(true));
		put(PROPERTY_MESSAGE, "");
	}

	public static R success(String msg) {
		R r = new R();
		r.put(PROPERTY_MESSAGE, msg);
		return r;
	}

	public static R success() {
		return new R();
	}

	public static R error(String msg) {
		R r = new R();
		r.put(PROPERTY_SUCCESS, Boolean.valueOf(false));
		r.put(PROPERTY_MESSAGE, msg);
		return r;
	}
	
	public static R serverError() {
		R r = new R();
		r.put(PROPERTY_SUCCESS, Boolean.valueOf(false));
		r.put(PROPERTY_MESSAGE, SERVER_ERROR);
		return r;
	}
	
	public static R paramsError() {
		R r = new R();
		r.put(PROPERTY_SUCCESS, Boolean.valueOf(false));
		r.put(PROPERTY_MESSAGE, PARAMS_ERROR);
		return r;
	}

	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}

	public R fluentPutAll(Map<? extends String, ? extends Object> m) {
		super.fluentPutAll(m);
		return this;
	}
}